'use strict';
exports.main = async (event, context) => {
	const { code } = event
	
	try {
		// 获取手机号
		const res = await uniCloud.getPhoneNumber({
			appid: context.APPID,
			provider: 'univerify',
			code: code
		})
		
		// 获取手机号成功
		const { phoneNumber } = res
		
		// 这里可以添加用户信息入库逻辑
		// const db = uniCloud.database()
		// await db.collection('users').add({
		// 	phone: phoneNumber,
		// 	create_time: Date.now()
		// })
		
		return {
			code: 0,
			message: '获取手机号成功'
		}
	} catch (e) {
		return {
			code: -1,
			message: e.message || '获取手机号失败'
		}
	}
} 